package com.hldsmart.smartda.activity.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.hldsmart.smartda.R;
import com.hldsmart.smartda.adapter.home.CommentAdapter;
import com.hldsmart.smartda.adapter.home.ParentAdapt;
import com.hldsmart.smartda.base.BaseActivity;
import com.hldsmart.smartda.model.entity.Comment;
import com.hldsmart.smartda.model.entity.ShowEntity;

import java.util.ArrayList;
import java.util.List;


public class MorenewsActivity extends BaseActivity {

    private ArrayList<ShowEntity> mParentList;
    private ListView lv_morenews_lv;
    private List<Comment> morenewsList;
    private CommentAdapter commentAdapter;
    private ParentAdapt mParentAdapt;
    public static void startMorenewsActivity(Context context) {
        Intent intent = new Intent(context, MorenewsActivity.class);
        context.startActivity(intent);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_morenews);
        initData();
        initView();


    }
    private void initData() {
        mParentList = new ArrayList<ShowEntity>();
        mParentList.clear();
            ShowEntity tempEntity = new ShowEntity("抹茶", "我大学党一枚身高165cm体重50kg，穿什么回家比较显气质大家有推荐吗","提问于2017-2-14");
            ShowEntity tempEntity1 = new ShowEntity("起点", "情人节快到了，想给女朋友一个惊喜，不知道买什么礼物好，求推荐？","提问于2017-2-14");
            mParentList.add(tempEntity);
            mParentList.add(tempEntity1);
        }


    private void initView() {
        ListView listView = (ListView) findViewById(R.id.listView1);
        mParentAdapt = new ParentAdapt(this, mParentList);
        listView.setAdapter(mParentAdapt);
        listView.setOnItemClickListener(new AdaptItemClick());

        //长按listview就不写示范了
//		listView.setOnItemLongClickListener(listener);
    }

    //父listview的单击事件的监听
    private class AdaptItemClick implements AdapterView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {
            if (ParentAdapt.mParentItem == position && ParentAdapt.mbShowChild) {
                ParentAdapt.mbShowChild = false;
            }else {
                ParentAdapt.mbShowChild = true;
            }
            ParentAdapt.mParentItem = position;
            mParentAdapt.notifyDataSetChanged();
        }
    }


}
